@extends('backstage.layout.master')
@section('title', '产品模板尺码列表')
@section('content')
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a href="backstage/home">主页</a>
            </li>

            <li class="active">
                <a href="/backstage/product-temp/product-temp-list">产品模板</a>
            </li>
            <li>
                产品列表
            </li>
        </ul><!-- .breadcrumb -->

        <div class="nav-search" id="nav-search">
        </div><!-- #nav-search -->
    </div>

    <div class="page-content">
        <div class="page-header">
            <h1>
                产品
                <small>
                    <i class="icon-double-angle-right"></i>
                    产品列表
                </small>
                <span class="pull-right">
                    <button class="btn btn-primary" onclick="javascript:window.location.href='{{asset('')}}backstage/product-temp/update-product-temp-size-format?id={{isset($product_temp->product_temp_id)?$product_temp->product_temp_id:''}}';">更新尺码格式</button>
                </span>
            </h1>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <h3 class="header smaller lighter red">产品模板简介：</h3>
                <div class="well">
                    <h4 class="green smaller lighter">产品模板参数</h4>
                    1、模板名称：{{isset($product_temp->name)?$product_temp->name:""}}</br>
                    2、模板Id：{{isset($product_temp->brand_id)?$product_temp->brand_id:""}}</br>
                    3、品牌：{{isset($product_temp->brand_name)?$product_temp->brand_name:""}}</br>
                    4、分类：{{isset($product_temp->temp_category_name)?$product_temp->temp_category_name:""}}</br>
                </div>
            </div>
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="table-responsive">
                    <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 尺码格式: </label>
                    <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                        <tr>
                            <td>
                                模板Id:
                            </td>
                            <td>
                                <input type="text"  readonly value="{{isset($product_temp->product_temp_id)?$product_temp->product_temp_id:''}}" style="width:70%;"  class="col-xs-10 col-sm-5"/>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                尺码格式(以|划分):
                            </td>
                            <td>
                                <input type="text"  readonly value="{{isset($temp_size_format->size_list)?$temp_size_format->size_list:''}}"style="width:70%;"  class="col-xs-10 col-sm-5"/>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                测量方式(图):
                            </td>
                            <td class="hidden-480"><img src="{{isset($temp_size_format->measure_method_image)?$temp_size_format->measure_method_image:''}}" width="70%" ></td>
                        </tr>
                    </table>
                </div>
                <div class="table-responsive">
                    <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 尺码详情: </label>
                    <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th class="center">
                                <label>
                                    <input type="checkbox" class="ace">
                                    <span class="lbl"></span>
                                </label>
                            </th>
                            <th>Id</th>
                            <th>尺码名</th>
                            <th width="40%">尺码详情</th>
                            <th>更新时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>

                        <tbody>
                        @foreach ($temp_sizes as $temp_size)
                        <tr class="" data-tr-id="{{isset($temp_size->id)?$temp_size->id:0}}">
                            <td class="center">
                                <label>
                                    <input type="checkbox" class="ace">
                                    <span class="lbl"></span>
                                </label>
                            </td>
                            <td>
                                {{isset($temp_size->id)?$temp_size->id:''}}
                            </td>
                            <td>
                                {{isset($temp_size->size_name)?$temp_size->size_name:''}}
                            </td>
                            <td >
                                <input type="text" name="size_values" value="{{isset($temp_size->size_values)?$temp_size->size_values:''}}" class="size_values">
                                <input type="hidden" value="{{isset($temp_size->id)?$temp_size->id:0}}">
                                <input  type="button" value="修改" class="button uptdate_size_values" >
                            </td>
                            <td>
                                {{isset($temp_size->updated_at)?date('Y-m-d H:i:s',$temp_size->updated_at):''}}
                            </td>
                            <td class="center" style="width:68px;">
                                <div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">
                                    <a title="删除" style="color:#d77600;cursor: pointer;" data-delete="{{isset($temp_size->id)?$temp_size->id:0}}">
                                        <i class="icon-trash bigger-130"></i>
                                    </a>
                                </div>
                            </td>
                        </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
                <div class="row">
                    <div class="col-sm-6">
                        <div class="dataTables_info" id="sample-table-2_info"></div>
                    </div>
                    <div class="col-sm-6">
                        <div class="dataTables_paginate paging_bootstrap">
                            <?php echo $temp_sizes->render(); ?>
                        </div>
                    </div>
                </div>
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
@stop
@section('script')
    <script type="text/javascript">
        $(function () {
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
            $('[data-rel=tooltip]').tooltip();
            $('[data-delete]').click(function(){
                var  id = $(this).attr("data-delete");
                if(id!==0){
                    swal({
                        title: "确定删除？？",
                        text: "",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        closeOnConfirm: true,
                        closeOnCancel: true
                    },function (){
                        $.ajax({
                            type: "POST",
                            url: "/backstage/product-temp/del-product-temp-size",
                            data: {'id':id},
                            success: function (msg) {
                                if(msg.state=1){
                                    swal({title: "删除成功！", text: "",type: "success", timer:1000 })
                                    $('[data-tr-id='+id+']').remove();
                                }else {
                                    swal({title: msg.message, text: "",type: "error", timer:1000 })
                                }

                            }, error: function () {
                                swal({title: "系统繁忙！", text: "",type: "error", timer:1000 })
                            }
                        });
                    });
                }
            });
            $('table th input:checkbox').on('click' , function(){
                var that = this;
                $(this).closest('table').find('tr > td:first-child input:checkbox')
                        .each(function(){
                            this.checked = that.checked;
                            $(this).closest('tr').toggleClass('selected');
                        });

            });
            $(".uptdate_size_values").click(function(){
                var id = $(this).prev().val();
                var size_values = $(this).prev().prev().val();
                var a = $(this);
                if(size_values==''){
                    return false;
                }
                $.ajax({
                    type: "POST",
                    url: "/backstage/product-temp/update-product-temp-size-values",
                    data: {'id':id,'size_values':size_values},
                    success: function (msg) {
                        if(msg.state==1){
                            swal({title: "更新成功！", text: "",type: "success", timer:1000 })
                        }else {
                            swal({title: msg.message, text: "",type: "error", timer:1000 })
                        }

                    }, error: function () {
                        swal({title: "系统繁忙！", text: "",type: "error", timer:1000 })
                    }
                });
            });
        });
    </script>
@stop